﻿using System;
using System.Collections.Generic;
using System.Text;
using TileGert;

namespace TestApp.Tests
{
  class RectangleClosestPoint : TestGame
  {
    private GertRectangle _rect = null;
    private GertPoint _point = null;
    private GertPoint _closest = null;

    protected override void AfterInit()
    {
      _rect = new GertRectangle(300, 150, 500, 450);
      _point = new GertPoint(600, 300);
    }

    protected override void Update(float timestep)
    {
      int step = 100;
      Input.Update();
      if (Input.Keyboard.KeyIsPressed(GertKeys.LeftArrow))
        _point.X -= step * timestep;
      if (Input.Keyboard.KeyIsPressed(GertKeys.RightArrow))
        _point.X += step * timestep;
      if (Input.Keyboard.KeyIsPressed(GertKeys.UpArrow))
        _point.Y -= step * timestep;
      if (Input.Keyboard.KeyIsPressed(GertKeys.DownArrow))
        _point.Y += step * timestep;

      _closest = _rect.ClosestPoint(_point);
    }

    protected override void Render()
    {
      Renderer.Clear(GertColor.Navy);
      Renderer.Begin();

      Renderer.ForegroundColor = GertColor.White;
      Renderer.DrawRectangle(_rect);
      Renderer.DrawPoint(_point);

      Renderer.ForegroundColor = GertColor.Red;
      Renderer.DrawPoint(_closest);

      Renderer.End();
    }

  }
}
